function add0(m: number) {
  return m < 10 ? '0' + m : m
}

export function formatTime(Time: string) {
  //shijianchuo是整数，否则要parseInt转换
  var time = new Date(parseInt(Time))
  var y = time.getFullYear()
  var m = time.getMonth() + 1
  var d = time.getDate()
  var h = time.getHours()
  var mm = time.getMinutes()
  var s = time.getSeconds()
  return y + '-' + add0(m) + '-' + add0(d) + '  ' + add0(h) + ':' + add0(mm) + ':' + add0(s)
}

export function getOffsetTopToBody(dom: HTMLElement) {
  let bodyDom: HTMLElement | null | undefined = dom
  let localTop = dom.offsetTop
  if (bodyDom.offsetTop === 50) {
    localTop = dom.offsetTop
  } else {
    while (bodyDom?.offsetTop !== 50) {
      bodyDom = bodyDom?.parentElement
      if (bodyDom) localTop += bodyDom.offsetTop
    }
  }
  return {
    bodyDom,
    localTop
  }
}

export function bounded(fn: Function, time: number) {
  let again = true
  return function() {
    if (again) {
      again = false
      setTimeout(() => {
        again = true
      }, time)
      return fn
    }
  }
}

export function bb(this: any) {
  ;(this as any).zz++
}
